﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Data;
using System.Data.Common;
using System.Data;
using JKF.Substructure;

namespace JKF.DataModule.SqlServerDAL
{
    public partial class dalPermission:IDAL.IdalPermission
    {
        #region IdalPermission 成员
        /// <summary>
        /// 根据当前用户ID，及访问的模块名称英文来获取相应的操作权限
        /// </summary>
        /// <param name="module_name_en"></param>
        /// <param name="user_key"></param>
        /// <returns></returns>
        public void GetUserPermission(string module_name_en, Guid role_key,ref bool preview,ref bool add,ref bool edit,ref bool delete)
        {
            int action_name_preview = -1, action_name_add = -1, action_name_edit = -1, action_name_delete = -1;
            Database db = DB.HR; 
            DbCommand dbCommand = db.GetStoredProcCommand("[dbo].[proc_GetUserCallModuleByID_Name]");
            db.AddInParameter(dbCommand, "@role_key", DbType.Guid, role_key);
            db.AddInParameter(dbCommand, "@module_name_en", DbType.String, module_name_en);
            db.AddOutParameter(dbCommand, "@action_name_preview", DbType.Int32, action_name_preview);
            db.AddOutParameter(dbCommand, "@action_name_add", DbType.Int32, action_name_add);
            db.AddOutParameter(dbCommand, "@action_name_edit", DbType.Int32, action_name_edit);
            db.AddOutParameter(dbCommand, "@action_name_delete", DbType.Int32, action_name_delete);
            db.ExecuteNonQuery(dbCommand);
            //获取返回结果 
            preview = Convert.ToInt32(dbCommand.Parameters["@action_name_preview"].Value.ToString()) > 0;
            add = Convert.ToInt32(dbCommand.Parameters["@action_name_add"].Value.ToString()) > 0;
            edit = Convert.ToInt32(dbCommand.Parameters["@action_name_edit"].Value.ToString()) > 0;
            delete = Convert.ToInt32(dbCommand.Parameters["@action_name_delete"].Value.ToString()) > 0;
        }

        /// <summary>
        /// 根据当前模块名称，及角色ID获取全部操作DataTable数据
        /// </summary> 
        /// <returns>返回全部操作权限数据</returns>
        public DataTable GetUserRolePermission()
        {
            Database db = DB.HR;
            DbCommand dbCommand = db.GetStoredProcCommand("[dbo].[proc_GetUserPermission]");
            return db.ExecuteDataSet(dbCommand).Tables[0];
        } 
        #endregion
    }
}
